﻿using AudioStudio;
using AudioStudio.Tools;
using UnityEngine;
using Yoozoo.UI.YGUI;

namespace Yoozoo.Gameplay.Managers
{
    // 想对YGUI的组件做点什么操作都放这里
    // 也是对Lua调用的接口


    public static class GuiManager
    {
        public static void Initialize()
        {
            // 设置按钮音效回调
            YButton.OnClickAudio += PlayButtonSound;
            YToggle.OnClickAudio += PlayToggleSound;
            YDropDown.OnClickAudio += PlayDropdownSound;
        }

        private static void PlayButtonSound(GameObject gameObject, string name)
        {
            if (string.IsNullOrEmpty(name))
                return;

            if (!gameObject)
                return;
            
            AudioManager.PlayGlobalSound(name, gameObject, AudioTriggerSource.ButtonSound);
        }

        private static void PlayToggleSound(GameObject gameObject, string name)
        {
            if (string.IsNullOrEmpty(name))
                return;

            if (!gameObject)
                return;

            AudioManager.PlayGlobalSound(name, gameObject, AudioTriggerSource.ToggleSound);
        }

        private static void PlayDropdownSound(GameObject gameObject, string name)
        {
            if (string.IsNullOrEmpty(name))
                return;

            if (!gameObject)
                return;

            AudioManager.PlayGlobalSound(name, gameObject, AudioTriggerSource.DropdownSound);
        }

        /// <summary>
        /// 指定某个精灵路径，必须强制卸载，一般是很大的图集
        /// </summary>
        /// <param name="dir"></param>
        public static void AddForceReleaseDir(string dir)
        {
            YImageBinder.AddForceReleaseDir(dir);
        }
    }
}
